package com.thread.Demo03;

//测试守护线程
//God bless you
public class TestDaemon {
    public static void main(String[] args) {
        God god = new God();
        You you = new You();
        Thread thread = new Thread(god);
        thread.setDaemon(true);//默认是false 用户线程

        thread.start();

        //用户线程
        new Thread(you).start();

        /*
               29999 days has gone!
               ====finally,good bye!====//用户线程终止
               God bless you! //守护线程仍在继续,虚拟机关闭需要时间
        */
    }
}

//God forever
class God implements Runnable{
    @Override
    public void run() {
        while(true) {
            System.out.println("God bless you!");
        }
    }
}

//You
class  You implements  Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 30000; i++) {
            System.out.println(i+" days has gone!");
        }
        System.out.println("====finally,good bye!====");
    }
}